package uk.ac.ebi.bioinvindex.model.impl.term;

import uk.ac.ebi.bioinvindex.model.impl.AnnotatableImpl;
import uk.ac.ebi.bioinvindex.model.impl.term.PropertyRole;

import javax.persistence.*;
import java.util.Collection;
import java.util.HashSet;

/**
 * User: Nataliya Sklyar (nsklyar@ebi.ac.uk)
 * Date: Jul 13, 2007
 */
@Entity
@Table(name = "PROPERTY")
@DiscriminatorColumn(name = "obj_type", discriminatorType = DiscriminatorType.STRING, length = 255)

public abstract class PropertyImpl<PVType extends FreeTextTermImpl> extends FreeTextTermImpl {

//	private String value;

	private PropertyRole role;

	private int order;

	private Collection<PVType> propertyValues = new HashSet<PVType>();

	protected PropertyImpl() {
	}

	protected PropertyImpl(String value, PropertyRole role, int order) {
		super(value);
		this.role = role;
		this.order = order;
	}

	protected PropertyImpl(PropertyRole role, int order) {
		this.role = role;
		this.order = order;
	}


	public PropertyRole getRole() {
		return role;
	}

	public void setRole(PropertyRole role) {
		this.role = role;
	}


	@Column(name = "position")
	public int getOrder() {
		return order;
	}

	@OneToMany(
			targetEntity = uk.ac.ebi.bioinvindex.model.impl.term.OntologyTermImpl.class
	)
	@JoinTable(
			name = "Property2OE",
			joinColumns = {@JoinColumn(name = "PROPERTY_ID")},
			inverseJoinColumns = @JoinColumn(name = "OE_ID")
	)
	public Collection<OntologyTermImpl> getOntologyTerms() {
		return super.getOntologyTerms();
	}

	protected void setOrder(int order) {
		this.order = order;
	}

	@OneToMany(targetEntity = uk.ac.ebi.bioinvindex.model.impl.term.PropertyValueImpl.class,
			mappedBy = "type")
	public Collection<PVType> getPropertyValues() {
		return propertyValues;
	}

	public void addPropertyValue(PVType value) {
		getPropertyValues().add(value);
	}


	protected void setPropertyValues(Collection<PVType> propertyValues) {
		this.propertyValues = propertyValues;
	}

	@Override
	public String toString() {
		return "PropertyImpl{ " +
				"ID = " + getId() +
				" Value = " + getValue() +
				" }";
	}

}
